<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<script src="../js/jquery-3.1.1.js" type="text/javascript"></script>
	<script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
	<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<script type="text/javascript">
	// 监听所有input

	
	$(document).keypress(function(e) {
		if (e.which == 13) {
			add_checkin_dormitory();
		}
	});

	$(document).ready(function () { 

		$.ajax({
			url : 'http://localhost:8080/Hello/dormitory/get_checking_dormitory_info.do',
			type : 'post',
			data : { },
			dataType : 'json',
			success : function(data) {

				console.log(data);
				show_dormitory_info(data);
				$("#dormitory_location").text(data.dormitory_zoom1+data.dormitory_zoom2+data.dormitory_zoom3);
				$('#head_student_name').text(data.head_student_name);
				$('#head_student_id').text(data.head_student_id);
				$('#counselor_name').text(data.counselor_name);
				$('#counselor_phone').text(data.counselor_phone);
				$('#counselor_id').text(data.counselor_id);
				var members=data.members;
				console.log(members);
				$.each(members,function(name,value) {
					console.log(name);  
					console.log(value);        
					$('#checkin_table').append(
						"<tr>"
						+"<td id="+name+"_student_id>"+value.student_id+"</td>"
						+"<td id="+name+"_banji_name>"+value.banji_name+"</td>"
						+"<td id="+name+"_student_name>"+value.student_name+"</td>"
						+"<td id="+name+"_parent_phone>"+value.parent_phone+"</td>"
						+"<td id="+name+"_head_teacher_name>"+value.head_teacher_name+"</td> "
						+"<td id="+name+"_head_teacher_phone>"+value.head_teacher_phone+"</td>"
						+"<td><span><input type='radio' id='"+name+"_result' name='"+name+"_result' value='1'>在寝</span></td>"
						+"<td><span><input type='radio' id='"+name+"_result' name='"+name+"_result' value='2'>请假</span></td>"
						+"<td><span><input type='radio' id='"+name+"_result' name='"+name+"_result' value='3'>失联</span></td>"


						+"</tr> "
						);
				});
			},
			error : function(data) {
				console.log("网络错误");
			}
		})
		

	}); 

	function show_dormitory_info(data){
		$('#dormitory_location').html("Hello");
		$("#dormitory_location").text(data.dormitory_zoom1+data.dormitory_zoom2+data.dormitory_zoom3);
	}

	function submit(){
		var member_length=$('#checkin_table').find("input").length/3;
		console.log(member_length);
		var result=[];
		// for(var j=0;j<member_length;j++){
		// 	result.push({"member_"+i:"0"});
		// }
		var member='';
		for(var i=0;i<member_length;i++){
			var result_idt="input[name='member_"+i+"_result']:checked";
			var student_id_idt="#member_"+i+"_student_id";
			var student_name_idt="#member_"+i+"_student_name";
			var member_name="member_"+i;

			console.log($(result_idt).val()+"/"+$(student_id_idt).text()+"/"+$(student_name_idt).text());

		    
		    member+=$(student_id_idt).text()+","+$(result_idt).val()+"&&";
		    // member.push($(student_id_idt).text());
		    // member.push($(result_idt).val());
		    // result.push(member);

			
		}
		console.log(result);
		$.ajax({
			url : 'http://localhost:8080/Hello/dormitory/checkin_dormitory.do',
			type : 'post',
			data : { 
				"result":member
			},
			dataType : 'json',
			success : function(data) { 
				console.log(data);
			},
			error : function(data) {
				console.log("失败");
			}
		})

	} 




 
</script>
<title>寝室长点名</title>
</head>
<body>  
	<div class="container-fluid">
		<div class="row" style="margin-top: 10px ">
			<div class="col-md-2"></div>
			<div class="col-md-2"><h1>寝室考勤</h1></div>
			<div class="col-md-4"></div>
			<div class="col-md-4"></div>
		</div>
		<div class="row" style="margin-top: 10px ">
			<div class="col-md-4"></div>
			<div class="col-md-4"><p id="dormitory_location">dormitory_location</p></div>
			<div class="col-md-4"></div>
		</div>
		<div class="row" style="margin-top: 10px "> 
			<div class="col-md-2"></div> 
			<div class="col-md-3" ">
				寝室长： <span id="head_student_name"> head_student_name</span>   
			</div>
			<div class="col-md-1">
				<div  id="head_student_id" style="display: none;">
				</div>
			</div>
			<div class="col-md-5" >
				宿管员：<span id="counselor_name"> counselor_name</span>
				,联系方式： <span id="counselor_phone"> counselor_phone</span>
			</div>

			<div class="col-md-1">
				<div >
					<span  id="counselor_id" style="display: none;"></span>
				</div>
			</div>
		</div>
		<div class="row" style="margin-top: 10px ">
			<div class="col-md-2"></div>
			<div class="col-md-8">
				<table class="table table-bordered table-hover" id="checkin_table">
					<tr>
						<td>学生学号</td>
						<td>所在班级</td>
						<td>学生姓名</td>
						<td>学生联系方式</td>
						<td>班主任</td> 
						<td>班主任联系方式</td>
						<td colspan="3">点名结果</td>
					</tr>   
					
				</table>    

			</div>  
			<div class="col-md-2"></div> 
		</div> 


		<div class="row" style="margin-top: 10px ">
			<div class="col-md-2"></div>
			<div class="col-md-7"></div>
			<div class="col-md-3"><button class="btn btn-success" id="submit" onclick="submit()">提交</button></div>
		</div>
	</div>   
</body> 
</html> 